/*
 * 10字符串比较.c
 *
 *  Created on: 2024年3月10日
 *      Author: HP
 */
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<time.h>

int my_strcmp(const char* s1, const char* s2){
	while(*s1 == *s2){
		if(*s1 == '\0'){
			return 0;
		}
		s1++;
		s2++;
	}
	return *s1>*s2?1:-1;
}

int my_strncmp(const char* s1, const char* s2, size_t n){
	for(int i=0; i<n && s1[i] && s2[i]; i++){
		if(s1[i] != s2[i]){
			return s1[i] > s2[i] ? 1: -1;
		}
	}
	return 0;
}

int main0710(){
	char ch1[] = "hello world";
	char ch2[] = "hello world";
	//int value = my_strcmp(ch1, ch2);
	int value = my_strncmp(ch1, ch2, 3);
	printf("%d\n", value);
	return 0;
}
